package com.briup.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.demo.bean.CmsCategory;
import com.briup.demo.common.Response;
import com.briup.demo.service.CmsCategoryService;

@RestController
@RequestMapping("/category")
public class CmsCategoryController {
	
	@Autowired
	CmsCategoryService categoryService;

	@PostMapping("/saveOrUpdate")
	public Response<String> saveOrUpdate(
			CmsCategory category){
		categoryService.saveOrUpdate(category);
		return Response.ok("操作成功！");
	}
	
	@DeleteMapping("/deleteById")
	public Response<String> deleteById(String id){
		int count = categoryService.deleteById(id);
		return Response.ok("删除成功"+count+"条栏目！");
	}
	
	@DeleteMapping("/deleteByIds")
	public Response<String> deleteByIds(String[] ids){
		int count = categoryService.batchDelete(ids);
		return Response.ok("成功删除"+count+"个栏目！");
	}
	
	@GetMapping("/all")
	public Response<List<CmsCategory>> findAll(){
		List<CmsCategory> all = categoryService.findAll();
		return Response.ok(all);
	}
}
